package com.neuedu.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 项目：      spring-framework
 * 类名:       StudentController
 * 创建时间：  2024/3/18 14：25
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@Controller
@RequestMapping("/teacher")
public class TeacherController {


    /**
    * http://ip：port/contextPath/controller
     *
     * http://localhost:8080/web/teacher/list
     * @param response
     * @throws IOException
     */
//    @RequestMapping(value = "/list",method = RequestMethod.POST )
    @GetMapping(value = "/list")
    @PostMapping(value = "/list")
    public void list(HttpServletRequest request ,HttpServletResponse response) throws IOException, ServletException {
        PrintWriter writer = response.getWriter();
//        response.setCharacterEncoding("utf-8");
//        response.setContentType("text/html;charset=utf-8");
//        writer.write("<h1>list -teacher</h1>");
//        writer.flush();
//        writer.close();

//        request.getRequestDispatcher("/WEB-INF/views/teacher.jsp").forward(request,response);



    }


    @RequestMapping(value = "/save",params = {"name","!password"})
    public void save(HttpServletResponse response) throws IOException {
        PrintWriter writer = response.getWriter();
        writer.write("<h1>保存成功</h1>");
        writer.flush();
        writer.close();
    }

    /**
     * http://localhost:8080/web/teacher/udpate?id=1&name=admin&is_del=0
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "/udpate",params = {"id","name!=admin","is_del=0"})
    public void udpate(HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.write("<h1>更新</h1>");
        writer.flush();
        writer.close();
    }


    /**
     * Refer:
     * @param response
     * @throws IOException
     *
     * /WEB-INF/jsp/delete.jsp
     */
    @RequestMapping(value = "delete",headers = {"User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"})
    public void delete(HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.write("<h1>删除</h1>");
        writer.flush();
        writer.close();
    }





}
